package com.epam.task.web.dao;

import java.sql.*;

public class ExecutePreparedStatement {
    public static void main(String[] args) {
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            Class.forName("org.gjt.mm.mysql.Driver");
            con = DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1/test","root", "123456");
                    String sql = "INSERT INTO students(name,id_group) VALUES( ?,?)";
            PreparedStatement ps = con.prepareStatement(sql);
            insert(ps, "Кукушнин", 851001);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    static void insert(PreparedStatement ps, String name, int idGroup)
            throws SQLException {
        ps.setString(1, name);
        ps.setInt(2, idGroup);
        ps.executeUpdate();
    }
}

